#coding=utf-8
from urllib import request
import re
import time


def getHtml():
    url = "http://www.xiaohua100.cn/index.html"
    data = request.urlopen(url).read().decode("utf-8")
    return data

def getImgUrl():
    imgurl = []
    data = getHtml()
    result = re.findall(r"<img.*?(?:>|\/>)",data)
    for i in result:
        imgurl.append(re.findall(r"src=\'(.*.jpg)",i))
    return imgurl

def getImg(filename,url):
    with request.urlopen(url) as f:
        data = f.read()
        with open(str(filename)+".jpg", mode="wb") as f:
            f.write(data)

def main():
    homeUrl = "http://www.xiaohua100.cn"
    li = getImgUrl()
    cout = 0
    for i in li:
        cout += 1
        if len(i):
            getImg(cout,homeUrl+str(i[0]))
if __name__ == '__main__':
    s = time.time()
    main()
    e = time.time()
    print("运行结束，用时%0.2fS"%(e-s))